package cate.game.play.buff.h;

import cate.common.util.XT;
import cate.game.play.base.HpCfg;
import cate.game.play.buff.BuffHandler;
import cate.game.play.config.PlayCfgArgs;
import cate.game.play.fighter.Fighter;
import cate.game.play.proce.action.ctx.ActionCtx;
import cate.game.play.proce.action.ctx.SkillActionCtx;

import java.util.List;

/**
 * 被攻击时100%对随机1个单位造成8%施法者生命值的伤害，每回合至多2次
 */
public class 复仇之雷BH extends BuffHandler {

	private int 概率;

	private HpCfg 血量配置;

	private int 次数;

	//概率=10000&血量配置=？？&次数=2
	@Override
	public void parse(String code) {
		PlayCfgArgs args = new PlayCfgArgs(code);
		概率 = args.getInt("概率", 0);
		血量配置 = new HpCfg(args);
		次数 = args.getInt("次数", 0);
	}

	private int roundTime;

	@Override
	public void onRoundBegin(ActionCtx action) {
		roundTime = 0;
	}

	@Override
	public void afterSufferOneAttack(SkillActionCtx action, long totalDamage, boolean strike) {
		if (roundTime >= 次数) {
			return;
		}
		if (!XT.chance(概率)) {
			return;
		}
		List<Fighter> targets = action.getTeamVs().getEnemyTeam(buff.owner.team).getFightersAlive(true);
		if (targets.isEmpty()) {
			return;
		}
		roundTime++;
		Fighter target = targets.get(0);
		double damage = 血量配置.settle(action.getActor(), target);
		target.attr.buffHurt(action, buff.owner, damage);
	}
}
